* Introducing bit field for database parameters
[lhc/web/wiklou.git] / includes / SpecialPage.php
1 <?php
2 global $wgSpecialPages;
3 $wgSpecialPages = array(
4 "Userlogin" => new UnlistedSpecialPage( "Userlogin" ),
5 "Userlogout" => new UnlistedSpecialPage( "Userlogout" ),
6 "Preferences" => new SpecialPage( "Preferences" ),
7 "Watchlist" => new SpecialPage( "Watchlist" ),
8 "Recentchanges" => new SpecialPage( "Recentchanges" ),
9 "Upload" => new SpecialPage( "Upload" ),
10 "Imagelist" => new SpecialPage( "Imagelist" ),
11 "Listusers" => new SpecialPage( "Listusers" ),
12 "Listadmins" => new SpecialPage( "Listadmins" ),
13 "Statistics" => new SpecialPage( "Statistics" ),
14 "Randompage" => new SpecialPage( "Randompage" ),
15 "Lonelypages" => new SpecialPage( "Lonelypages" ),
16 "Unusedimages" => new SpecialPage( "Unusedimages" )
17 );
18 global $wgDisableCounters;
19 if( !$wgDisableCounters )
20 {
21 $wgSpecialPages["Popularpages"] = new SpecialPage( "Popularpages" );
22 }
23 $wgSpecialPages = array_merge($wgSpecialPages, array (
24 "Wantedpages" => new SpecialPage( "Wantedpages" ),
25 "Shortpages" => new SpecialPage( "Shortpages" ),
26 "Longpages" => new SpecialPage( "Longpages" ),
27 "Newpages" => new SpecialPage( "Newpages" ),
28 "Ancientpages" => new SpecialPage( "Ancientpages" ),
29 "Deadendpages" => new SpecialPage( "Deadendpages" ),
30 "Allpages" => new SpecialPage( "Allpages" ),
31 "Ipblocklist" => new SpecialPage( "Ipblocklist" ),
32 "Maintenance" => new SpecialPage( "Maintenance" ),
33 "Specialpages" => new UnlistedSpecialPage( "Specialpages" ),
34 "Contributions" => new UnlistedSpecialPage( "Contributions" ),
35 "Emailuser" => new UnlistedSpecialPage( "Emailuser" ),
36 "Whatlinkshere" => new UnlistedSpecialPage( "Whatlinkshere" ),
37 "Recentchangeslinked" => new UnlistedSpecialPage( "Recentchangeslinked" ),
38 "Movepage" => new UnlistedSpecialPage( "Movepage" ),
39 "Blockme" => new UnlistedSpecialPage( "Blockme" ),
40 "Geo" => new UnlistedSpecialPage( "Geo" ),
41 "Validate" => new UnlistedSpecialPage( "Validate" ),
42 "Booksources" => new SpecialPage( "Booksources" ),
43 "Categories" => new SpecialPage( "Categories" ),
44 "Export" => new SpecialPage( "Export" ),
45 "Version" => new SpecialPage( "Version" ),
46 "Allmessages" => new SpecialPage( "Allmessages" ),
47 "Search" => new UnlistedSpecialPage( "Search" ),
48 "Blockip" => new SpecialPage( "Blockip", "sysop" ),
49 "Asksql" => new SpecialPage( "Asksql", "sysop" ),
50 "Undelete" => new SpecialPage( "Undelete", "sysop" ),
51 "Makesysop" => new SpecialPage( "Makesysop", "sysop" ),
52 # "Import" => new SpecialPage( "Import", "sysop" ),
53 "Lockdb" => new SpecialPage( "Lockdb", "developer" ),
54 "Unlockdb" => new SpecialPage( "Unlockdb", "developer" )
55 ));
56
57 class SpecialPage
58 {
59 /* private */ var $mName, $mRestriction, $mListed, $mFunction, $mFile;
60
61 /* static */ function addPage( &$obj ) {
62 global $wgSpecialPages;
63 $wgSpecialPages[$obj->mName] = $obj;
64 }
65
66 /* static */ function removePage( $name ) {
67 global $wgSpecialPages;
68 unset( $wgSpecialPages[$name] );
69 }
70
71 /* static */ function &getPage( $name ) {
72 global $wgSpecialPages;
73 if ( array_key_exists( $name, $wgSpecialPages ) ) {
74 return $wgSpecialPages[$name];
75 } else {
76 return NULL;
77 }
78 }
79
80 # Return categorised listable special pages
81 /* static */ function getPages() {
82 global $wgSpecialPages;
83 $pages = array(
84 "" => array(),
85 "sysop" => array(),
86 "developer" => array()
87 );
88
89 foreach ( $wgSpecialPages as $name => $page ) {
90 if ( $page->isListed() ) {
91 $pages[$page->getRestriction()][$page->getName()] =& $wgSpecialPages[$name];
92 }
93 }
94 return $pages;
95 }
96
97 # Execute a special page path, which may contain slashes
98 /* static */ function executePath( &$title ) {
99 global $wgSpecialPages, $wgOut, $wgTitle;
100
101 $bits = split( "/", $title->getDBkey(), 2 );
102 $name = $bits[0];
103 if( empty( $bits[1] ) ) {
104 $par = NULL;
105 } else {
106 $par = $bits[1];
107 }
108
109 $page =& SpecialPage::getPage( $name );
110 if ( is_null( $page ) ) {
111 $wgOut->setArticleRelated( false );
112 $wgOut->setRobotpolicy( "noindex,follow" );
113 $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
114 } else {
115 if($par !== NULL) {
116 $wgTitle = Title::makeTitle( NS_SPECIAL, $name );
117 } else {
118 $wgTitle = $title;
119 }
120
121 $page->execute( $par );
122 }
123 }
124
125 function SpecialPage( $name = "", $restriction = "", $listed = true, $function = false, $file = "default" ) {
126 $this->mName = $name;
127 $this->mRestriction = $restriction;
128 $this->mListed = $listed;
129 if ( $function == false ) {
130 $this->mFunction = "wfSpecial{$name}";
131 } else {
132 $this->mFunction = $function;
133 }
134 if ( $file === "default" ) {
135 $this->mFile = "Special{$name}.php";
136 } else {
137 $this->mFile = $file;
138 }
139 }
140
141 function getName() { return $this->mName; }
142 function getRestriction() { return $this->mRestriction; }
143 function isListed() { return $this->mListed; }
144
145 function userCanExecute( &$user ) {
146 if ( $this->mRestriction == "" ) {
147 return true;
148 } else {
149 if ( in_array( $this->mRestriction, $user->getRights() ) ) {
150 return true;
151 } else {
152 return false;
153 }
154 }
155 }
156
157 function displayRestrictionError() {
158 global $wgOut;
159 if ( $this->mRestriction == "developer" ) {
160 $wgOut->developerRequired();
161 } else {
162 $wgOut->sysopRequired();
163 }
164 }
165
166 function setHeaders() {
167 global $wgOut;
168 $wgOut->setArticleRelated( false );
169 $wgOut->setRobotPolicy( "noindex,follow" );
170 $wgOut->setPageTitle( $this->getDescription() );
171 }
172
173 function execute( $par ) {
174 global $wgUser, $wgOut, $wgTitle;
175
176 $this->setHeaders();
177
178 if ( $this->userCanExecute( $wgUser ) ) {
179 if ( $this->mFile ) {
180 require_once( $this->mFile );
181 }
182 $func = $this->mFunction;
183 $func( $par );
184 } else {
185 $this->displayRestrictionError();
186 }
187 }
188
189 function getDescription() {
190 return wfMsg( strtolower( $this->mName ) );
191 }
192
193 function getTitle() {
194 return Title::makeTitle( NS_SPECIAL, $this->mName );
195 }
196
197 function setListed( $listed ) {
198 return wfSetVar( $this->mListed, $listed );
199 }
200 }
201
202 class UnlistedSpecialPage extends SpecialPage
203 {
204 function UnlistedSpecialPage( $name, $restriction = "", $function = false, $file = "default" ) {
205 SpecialPage::SpecialPage( $name, $restriction, false, $function, $file );
206 }
207 }